# -*- coding: utf-8 -*-
class UserController < ApplicationController
  before_filter :user_authorize
  before_filter :sys_before_log
  
  def getAllUsers
    
    users = User.all
    jsonStr="{totalProperty:"+users.length.to_s+",root:"+users.to_json()+"}"
    
    puts jsonStr
    render :text=>jsonStr, :layout=>false
  end

  def createUser
    user = User.new
    user.name = params[:name]
    user.password = params[:password]
    user.save
    info = "成功"
    result = "{success:true,info:'#{info}'}"
    render :text=>result, :layout=>false
  end

  def editUser
    
    @user = User.find(params[:user_id])
    puts @user
    puts @user.name
  end

  def updateUser
    
    user = User.find(params[:user_id])
    user.name = params[:name]
    user.password = params[:password]
    user.save
    info = "成功"
    result = "{success:true,info:'#{info}'}"
    render :text=>result, :layout=>false
  end

  #解锁或加锁，互操作。
  def userLock
    user = User.find(params[:user_id])
    if user.id >1
      if user.is_locked == 1
        user.is_locked = 0
      else
        user.is_locked = 1
      end
      user.save
    end
    info = "成功"
    result = "{success:true,info:'#{info}'}"
    render :text=>result, :layout=>false
  end
end
